package org.jsea.meta.api.constant;

import lombok.Getter;

/**
 * --.
 * *
 * author   Jiang.hy
 * create   2022-04-09
 */
public enum WhereCond {
    eq("="),
    ne("!="),
    gt(">"),
    ge(">="),
    lt("<"),
    le("<="),
    in(".", " in "),
    not_in("!.", " not in "),
    //后端拼接%，避免前端输入框拼接出现问题
    like("*", " like "),
    not_like("!*", " not like "),
    left_like("{", " like "),
    right_like("}", " like "),
    not_left_like("!{", " not like "),
    not_right_like("!}", " not like "),
    between("~", " between "),
    not_between("!~", " not between "),
    is(":", " is "),
    is_not("!:", " is not ");
    @Getter
    private final String key;
    private String sql;

    WhereCond(String key) {
        this.key = key;
    }

    WhereCond(String key, String sql) {
        this.key = key;
        this.sql = sql;
    }

    public static WhereCond get(String symbol) {
        if (symbol == null) {
            return eq;
        }
        for (WhereCond value : WhereCond.values()) {
            if (symbol.equals(value.getKey()))
                return value;
        }
        throw new IllegalArgumentException("unsupported condition : " + symbol);
    }

    @Override
    public String toString() {
        return sql == null ? this.key : sql;
    }
}
